<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- plugin.cpp -->
  <title>Qt Quick Shared Image Provider | Qt Quick 5.11</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtquick-index.html">Qt Quick</a></td><td >Qt Quick Shared Image Provider</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.11.1 参考指南</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level2"><a href="#summary">摘要</a></li>
<li class="level2"><a href="#usage">用法</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Shared Image Provider</h1>
<span class="subtitle"></span>
<!-- $$$Qt.labs.sharedimage-description -->
<div class="descr"> <a name="details"></a>
<a name="summary"></a>
<h3 >Summary</h3>
<p>此模块提供了在多个Qt Quick应用程序使用相同的本地图像文件的用例中保存内存的功能。它将解码后的<a href="../qtgui/qimage.html">QImage</a>数据放在共享系统内存中，使所有进程都可以访问它(参见<a href="../qtcore/qsharedmemory.html">QSharedMemory</a>)。</p>
<p>这个模块只共享CPU内存。它不提供GPU内存或纹理的共享。</p>
<a name="usage"></a>
<h3 >Usage</h3>
<p>要使用此模块，请像这样导入它:</p>
<pre class="cpp">

  import <span class="type"><a href="../qtqml/qml-qtqml-qt.html">Qt</a></span><span class="operator">.</span>labs<span class="operator">.</span>sharedimage <span class="number">1.0</span>

</pre>
<p>共享功能是通过<a href="qquickimageprovider.html">QQuickImageProvider</a>提供的。对图像的URL源使用&quot;image:&quot;，后面跟着<i>shared</i>标识符，后面再跟着图像文件路径的方案。例如:</p>
<pre class="cpp">

  Image { source: <span class="string">&quot;image://shared/usr/share/wallpapers/mybackground.jpg&quot;</span> }

</pre>
<p>这将查找文件<i>/usr/share/wallpapers/mybackground.jpg</i>。第一个这样做的进程将使用常规的Qt图像加载读取图像文件。然后，解码后的图像数据将使用完整的文件路径作为键放在共享内存中。稍后，请求相同映像的进程将发现数据已经在共享内存中可用。然后他们将使用它而不是再次加载图像文件。</p>
<p>共享映像数据将一直保持可用，直到最后一个进程删除了对共享映像的最后一个引用，然后将自动释放该引用。</p>
<p>如果系统内存共享不可用，共享映像提供程序将恢复到正常的非共享映像加载。</p>
<p>文件路径必须是绝对的。要使用相对路径，请用<i>Qt.resolvedUrl()</i>以使其绝对，并且更改为URL路径方案。例如:</p>
<pre class="cpp">

  <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  property string imagePrefix: <span class="type"><a href="../qtqml/qml-qtqml-qt.html">Qt</a></span><span class="operator">.</span>resolvedUrl(<span class="string">&quot;../myimages/&quot;</span>)<span class="operator">.</span>replace(<span class="string">&quot;file://&quot;</span><span class="operator">,</span> <span class="string">&quot;image://shared/&quot;</span>)
  Image { source: imagePrefix <span class="operator">+</span> <span class="string">&quot;myimage.png&quot;</span> }

</pre>
<p>共享映像模块不提供任何直接可用的QML类型。</p>
</div>
<!-- @@@Qt.labs.sharedimage -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2018 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
